using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace BlockOS.Client
{
    public class Blink : MonoBehaviour
    {
        [SerializeField]
        private TMP_Text text;

        [SerializeField]
        private float periodTime;
        [Range(0f, 1f)]
        [SerializeField]
        private float showRate;

        private float showTime;
        private float timer = 0;

        private void Awake()
        {
            showTime = periodTime * showRate;
        }

        private void Update()
        {
            if (timer > periodTime)
            {
                timer = 0;
            }
            else
            {
                if (timer < showTime)
                {
                    text.maxVisibleCharacters = text.text.Length;
                }
                else
                {
                    text.maxVisibleCharacters = text.text.Length - 1;
                }
                timer += Time.deltaTime;
            }
        }
    }
}